/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/

#include "Object.h"
#include "World.h"
#include "owndebug.h"
#include "Primitive.h"
#include <typeinfo>

CObject::CObject(CWorld *World, CObject *ParentObject)
  : SimWorld(World),
    Parent(ParentObject),
    WorldID(World->WorldID),
    SpaceID(World->SpaceID),
    StaticSpaceID(World->StaticSpaceID)
{
  
}

CObject::~CObject()
{
  //dPrint(1,"deleting...");
  for (ObjectsIter i=Children.begin(); i != Children.end(); i++) {
      delete (CObject*)*i;
    }
  Children.clear();
  for (PrimitivesIter i=Parts.begin(); i != Parts.end(); i++)
    {
      delete (CPrimitive*)*i;
    }
  Parts.clear();
  //dPrint(1,"done deleting");
}

void CObject::Activate()
{
  for (ObjectsIter i=Children.begin(); i != Children.end(); i++)
  {
    (*i)->Activate();
  }
}

void CObject::Deactivate()
{
  std::string foo = typeid(*this).name();
  dPrint(ODTEST,"Warning: Instance '%s' does not implement Deactivate!", foo.c_str());
  /*  for (ObjectsIter i=Children.begin(); i != Children.end(); i++)
  {
    (*i)->Deactivate();
    }*/

}
